package com.yunhe.mybatis.web.deparment;

import com.yunhe.mybatis.entity.Deparment;
import com.yunhe.mybatis.service.impl.DeparmentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/deparment/update")
public class UpdateServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String bumen = req.getParameter("bumen");
        Integer deparmentId = Integer.valueOf(req.getParameter("deparmentId"));

        //定义输出流
        PrintWriter writer = resp.getWriter();
        //先判断是不是空
        if (null == bumen){
            writer.print("修改名称不为空");
        }else {
            Deparment deparment = new Deparment();
            deparment.setName(bumen);
            deparment.setId(deparmentId);

            DeparmentServiceImpl deparmentService = new DeparmentServiceImpl();
            deparmentService.update(deparment);
            req.getRequestDispatcher("/success.jsp").forward(req,resp);
        }

    }
}
